import { createStore } from 'vuex'
import menu from './modules/menu'
import role from './modules/role'
import user from './modules/user'

// interface userState {
//   userinfo: any,
  
// }
export default createStore({
  state: {
    // userinfo: sessionStorage.getItem('userinfo')
    userinfo: sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')+''): null
  },
  getters: {
    getUser(state){
      return state.userinfo
    }
  },
  mutations: {
    REQ_USERINFO(state,payload){
      if(payload){
        state.userinfo=payload
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
      }
    }
  },
  actions: {
    changeUserAction({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    role,
    user
  }
})
